package com.jp.knowledge.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.AttentionData;
import com.jp.knowledge.util.ImageLoadUtil;
import com.jp.knowledge.util.TimeUtil;

import java.util.List;

/**
 * Created by jiayen on 16/10/27.
 */

public class AttentionItemAdapter extends  JPBaseAdpter<AttentionData> {

    private int flag;
    public AttentionItemAdapter(Context context, List infos, int flag) {
        super(context, infos);
        this.flag=flag;
    }

    @Override
    protected int getLayoutId(int position) {
        return R.layout.attention_item;
    }

    @Override
    protected void renderData(JPViewHolder holder, AttentionData item, int position) {

        ImageView icon = holder.getView(R.id.icon);//图标
        TextView title = holder.getView(R.id.title);
        TextView description = holder.getView(R.id.descritption);
        TextView newNum = holder.getView(R.id.new_num);
        TextView newText = holder.getView(R.id.new_text);
        TextView companyName = holder.getView(R.id.company_name);
        TextView city = holder.getView(R.id.city);
        TextView count = holder.getView(R.id.count);
        TextView time = holder.getView(R.id.time);
        TextView attentionNum = holder.getView(R.id.attetion_num);
        TextView isCreate = holder.getView(R.id.is_create);//是否本人创建

        if(item.getType() == 3){            // 代表类型为公司，公司不显示图标
            icon.setVisibility(View.GONE);
        } else {
            icon.setVisibility(View.VISIBLE);
            ImageLoadUtil.loadrund(getContext(), item.getIcon() + "?imageView2/2/w/100/interlace/1", icon, 15);
        }
        if(item.getType() == 8){
            description.setVisibility(View.VISIBLE);
            setTextView(description, item.getSource());
        } else if(item.getType() == 9){
            description.setVisibility(View.VISIBLE);
            setTextView(description, item.getDesc());
        } else{
            description.setVisibility(View.GONE);
        }
        setTextView(city, item.getAddress());
        setTextView(title, item.getTitle());
        setTextView(newNum, item.getNewNum()+"");
        if(item.getNewNum() > 0){
            newNum.setTextColor(getContext().getResources().getColor(R.color.orange));
            newText.setTextColor(getContext().getResources().getColor(R.color.font_gray_think));
        } else{
            newNum.setTextColor(getContext().getResources().getColor(R.color.font_gray_think));
            newText.setTextColor(getContext().getResources().getColor(R.color.font_gray_think));
        }
        setTextView(companyName, item.getSource());
        setTextView(newText, item.getCountNum()+"数据");
        count.setVisibility(View.GONE);

        if("对手".equals(item.getPrompt())
                || "兄弟公司".equals(item.getPrompt())
                || "合作伙伴".equals(item.getPrompt())){
            attentionNum.setVisibility(View.GONE);
        } else {
            setTextView(attentionNum, item.getSubscribeNum() + "关注");
        }
        attentionNum.setVisibility(View.GONE);
        isCreate.setVisibility(View.GONE);
        setTextView(time, TimeUtil.friendly_time(item.getAttentionTime()));

        // 只显示时间，其他不显示
        companyName.setVisibility(View.GONE);
        city.setVisibility(View.GONE);
        count.setVisibility(View.GONE);
        attentionNum.setVisibility(View.GONE);
        isCreate.setVisibility(View.GONE);
    }

    private void setTextView(TextView textView, String text){
        if(text == null || text.trim().length() == 0){
            textView.setVisibility(View.GONE);
        } else{
            textView.setVisibility(View.VISIBLE);
            textView.setText(text);
        }
    }
}
